
/* 表单校验函数  */

//uid校验
function checkUid(el){
	var uid = el.val();
	if (!uid) {
    	layer.tips("SingleId不能为空", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
        return false;
    } else if (uid.length > 20 || uid.length < 5){
    	layer.tips("SingleId长度为5-20个字符", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	}
	el.parent().removeClass("has-error");
	return true;
};
//姓名校验
function checkName(el){
	var name = el.val();
	if(!name){
		layer.tips("姓名不能为空", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	} else if (name.length>10||name.length<2){
		layer.tips("输入合适长度的名字(2~10)个字符", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	} else if (!name.match(/^[\u4E00-\u9FFFA-Za-z]*$/)){
		layer.tips("姓名不能含有特殊字符和数字", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	}
	el.parent().removeClass("has-error");
	return true;
};
//密码校验
function checkPwd(el){
	var password = el.val();
    if (!password.match(/^[A-Za-z0-9]{6,15}$/)) {
        layer.tips("密码格式不正确<br>以字母开头的6-15数字或字母，注意区分大小写", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
        el.parent().addClass("has-error");
        return false;
    }
    el.parent().removeClass("has-error");
	return true;
};
//邮箱校验
function checkEmail(el){
	var mail = el.val();
	if(!mail){
		layer.tips("邮箱不能为空", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	} else if (!mail.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/)){
		layer.tips("请输入合法的邮箱", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	}
	el.parent().removeClass("has-error");
	return true;
};
//电话号码校验
function checkMobile(el){
	var mobile=el.val();
	if (mobile && !mobile.match(/^1[358][0-9]{9}$/g)){
		layer.tips("电话号码格式不正确", el, {
			tips: [1, '#3595CC'],
			time: 4000
   		});
		el.parent().addClass("has-error");
		return false;
	}
	el.parent().removeClass("has-error");
	return true;
};
//校验密码相同
function checkPwdSame(el1, el2){
	var val1=el1.val();
	var val2=el2.val();
	if (!val1){
		layer.tips("密码不能为空", el1, {
			tips: [1, '#3595CC'],
			time: 4000
		});
		el1.parent().addClass("has-error");
		return false;
	} else if (!val2){
		layer.tips("确认密码不能为空", el2, {
			tips: [1, '#3595CC'],
			time: 4000
		});
		el2.parent().addClass("has-error");
		return false;
	} else if(val1 != val2) {
		layer.tips("两次密码输入不一致", el2, {
			tips: [1, '#3595CC'],
			time: 4000
		});
		el2.parent().addClass("has-error");
		return false;
	}
	el1.parent().removeClass("has-error");
	el2.parent().removeClass("has-error");
	return true;
};